﻿using Caliburn.Micro;

namespace OPSYS_Schematic.UIInfrastructure
{
    /// <summary>
    /// A part that can be used as both <see cref="MenuPart"/> and <see cref="ToolBarPart"/>.
    /// </summary>
    public class MenuToolPart : PartBase, IMenuPart, IToolBarPart, IObservableParent<IMenuPart>,
                                IObservableParent<IToolBarPart>
    {
        #region Constructor

        public MenuToolPart()
        {
        }

        public MenuToolPart(string name)
            : base(name)
        {
        }

        #endregion

        #region PartBase

        public override void Execute()
        {
            var statusBar = IoC.Get<IStatusBarService>();
            statusBar.ShowMessage(DisplayName);
        }

        #endregion

        private readonly BindableCollection<IMenuPart> menus = new BindableCollection<IMenuPart>();
        private bool _isChecked;

        private bool _isSeparator;
        private string toolTip;

        #region IMenuPart Members

        public bool IsSeparator
        {
            get { return _isSeparator; }
            private set
            {
                _isSeparator = value;
                NotifyOfPropertyChange(() => IsSeparator);
            }
        }

        public bool IsCheckable { get; protected set; }

        public bool IsChecked
        {
            get { return _isChecked; }
            set
            {
                _isChecked = value;
                NotifyOfPropertyChange(() => IsChecked);
            }
        }

        #endregion

        #region IObservableParent<IMenuPart> Members

        IObservableCollection<IMenuPart> IObservableParent<IMenuPart>.Items
        {
            get { return menus; }
        }

        #endregion

        #region IPartParent<IToolBarPart> Memebers

        private readonly BindableCollection<IToolBarPart> toolbars = new BindableCollection<IToolBarPart>();

        IObservableCollection<IToolBarPart> IObservableParent<IToolBarPart>.Items
        {
            get { return toolbars; }
        }

        #endregion

        #region IToolBarPart Members

        public string ToolTip
        {
            get { return toolTip; }
            set
            {
                toolTip = value;
                NotifyOfPropertyChange(() => ToolTip);
            }
        }

        #endregion
    }
}